import axios from 'axios'

// const baseURL = 'http://193.112.55.79:9096/'
const baseURL = 'http://127.0.0.1:3000/'

axios.defaults.baseURL = baseURL

// 允许axios传递cookie数据，因为默认情况下，axios并不会传递cookie
axios.defaults.withCredentials = true

// 一级分类查询
export const categoryFirst = () => {
  return axios.get('/category/queryTopCategory')
    .then(res => {
      return res.data
    })
}

// 二级分类查询
export const categorySecond = (id) => {
  return axios.get('/category/querySecondCategory', {params: id})
    .then(res => {
      return res.data
    })
}
// 获取搜索的数据
export const getSearchData = (pa) => {
  return axios.get('/product/queryProduct', {params: pa})
    .then(res => {
      return res.data
    })
}

// 获取商品详情数据
export const getProductDetail = (id) => {
  return axios.get('/product/queryProductDetail', {params: {id: id}})
    .then(res => {
      return res.data
    })
}

// 加入购物车
export const addCart = (pa) => {
  return axios.post('/cart/addCart', pa)
    .then(res => {
      return res.data
    })
}
